$TITLE  GTAPinGAMS -- Static Multiregional Core Model in MPSGE Syntax

*	Note:

*		This is the model implemented in MPSGE.

*		This implementation accomodates both constant-elasticity of
*		transformation between production for domestic and export
*		markets (eta < +INF), and perfect substitution between 
*		those markets (eta=+INF).

*		Variables, equations and GAMS keywords are in UPPER case.
*		Sets and parameters are in lower case.

*	Read the dataset using the standard routine:

$if not set dataset $set dataset gtap5_small
$include mrtdata

SCALAR
	eta	Elasticity of transformation - domestic vs. exports	/ +inf /,
	esubdm	Elasticity of substitution - domestic vs. imports	/ 4 /,
	esubmm  Elasticity of substitution - imports			/ 8 /;

$ONTEXT

$MODEL:GTAP

$SECTORS:
        C(r)                    ! Private consumption
        G(r)                    ! Public provision
        Y(i,r)$vom(i,r)         ! Output
        M(i,r)$vim(i,r)         ! Import aggregation
        A(d,i,r)$va(d,i,r)      ! Armington aggregation of domestic and imports
        YT                      ! Transport 

$COMMODITIES:
        PC(r)				! Private demand
        PG(r)				! Public provision
	PY(i,r)$(vom(i,r) and (1/eta=0))! Output price
        PD(i,r)$(vdm(i,r) and 1/ETA)	! Domestic price
        PX(i,r)$(vxm(i,r) and 1/ETA)	! Export price
        PM(i,r)$vim(i,r)		! Import price
        PA(d,i,r)$va(d,i,r)	! Armington composite price
        PF(f,r)$evoa(f,r)	! Factor price
        PT                      ! Transport services

$CONSUMERS:
       RA(r)           ! Representative agent

*       Production:

$PROD:Y(i,r)$(vom(i,r)>0 and 1/eta>0)  S:0  T:eta  va:1
        O:PD(i,r)	Q:vdm(i,r)    A:RA(r) T:ty(i,r)
        O:PX(i,r)	Q:vxm(i,r)    A:RA(r) T:ty(i,r)
        I:PA("i",j,r)	Q:vafm(J,i,r) A:RA(r) T:ti(j,i,r) 
        I:PF(f,r)	Q:vfm(f,i,r)  P:pf0(f,i,r) A:RA(r) T:tf(f,i,r) va:

$PROD:Y(i,r)$(vom(i,r)>0 and 1/eta=0)  S:0  va:1
        O:PY(i,r)	Q:vom(i,r)    A:RA(r) T:ty(i,r)
        I:PA("i",j,r)	Q:vafm(J,i,r) A:RA(r) T:ti(j,i,r) 
        I:PF(f,r)	Q:vfm(f,i,r)  P:pf0(f,i,r) A:RA(r) T:tf(f,i,r) va:

$REPORT:
        V:FD(f,i,r)     I:PF(f,r)       PROD:Y(i,r)
        V:YD(i,r)$(1/eta>0) O:PD(i,r)       PROD:Y(i,r)
        V:YX(i,r)$(1/eta>0) O:PX(i,r)       PROD:Y(i,r)

*       Armington aggregation over domestic versus imports:

$PROD:A(d,i,r)$va(d,i,r)  S:esubdm
        O:PA(d,i,r)		Q:va(d,i,r)
        I:PD(i,r)$(1/eta>0)	Q:vd(d,i,r)
        I:PY(i,r)$(1/eta=0)	Q:vd(d,i,r)
        I:PM(i,r)		Q:vm(d,i,r)

*       Armington aggregation across imports from different countries:

$PROD:M(i,r)$(vim(i,r)>0 and 1/eta>0)   S:esubmm   s.TL:0
        O:PM(i,r)       Q:vim(i,r)
        I:PX(i,s)       Q:vxmd(i,s,r)  P:pmx0(i,s,r)	s.TL:
+                       A:RA(S) T:TX(i,s,r) A:RA(r) T:(tm(i,s,r)*(1+tx(i,s,r)))
        I:PT#(s)        Q:vtwr(i,s,r)  P:pmt0(i,s,r)	s.TL: 
+			A:RA(r) T:tm(i,s,r)

$PROD:M(i,r)$(vim(i,r)>0 and 1/eta=0)   S:esubmm   s.TL:0
        O:PM(i,r)       Q:vim(i,r)
        I:PY(i,s)       Q:vxmd(i,s,r)  P:pmx0(i,s,r)	s.TL:
+                       A:RA(S) T:TX(i,s,r) A:RA(r) T:(tm(i,s,r)*(1+tx(i,s,r)))
        I:PT#(s)        Q:vtwr(i,s,r)  P:pmt0(i,s,r)	s.TL: 
+			A:RA(r) T:tm(i,s,r)

*       Demand for public output:

$PROD:G(r)  S:1
        O:PG(r)         Q:vg(r)
        I:PA("g",i,r)   Q:vgm(i,r)  P:pg0(i,r)  A:RA(r) T:tg(i,r) 

*       Private consumption:

$PROD:C(r)  S:1
        O:PC(r)         Q:vp(r)
        I:PA("c",i,r)   Q:vpm(i,r)  P:pc0(i,r)  A:RA(r) T:tp(i,r)

*       Inter-national transport services (Cobb-Douglas):

$PROD:YT  S:1
        O:PT			Q:vt
        I:PX(i,r)$(1/eta>0)	Q:vst(i,r)
        I:PY(i,r)$(1/eta=0)	Q:vst(i,r)

*       Final demand over consumption, savings and government 
*       services (Cobb-Douglas):

$DEMAND:RA(r)  
        E:PF(f,r)		Q:evoa(f,r)
        E:PC(num)		Q:vb(r)
        E:PD(cgd,r)$(1/eta>0)	Q:-vi(r)
	E:PY(cgd,r)$(1/eta=0)	Q:-vi(r)
        E:PG(r)			Q:-vg(r)
        D:PC(r)			Q:vp(r)

$OFFTEXT
$SYSINCLUDE mpsgeset GTAP

*	Check the benchmark:

GTAP.ITERLIM = 0;
$INCLUDE GTAP.GEN
SOLVE GTAP USING MCP;


*	Fix a numeraire to permit comparison with MCP:

RA.FX(num) = RA.L(num);

*	Do a cleanup calculation:

GTAP.ITERLIM = 8000;
$INCLUDE GTAP.GEN
SOLVE GTAP USING MCP;

display ty, tp, tx, tm;



*	Illustrate how to recover demands from the solution
*	using Cobb-Douglas compensated demand functions:

parameter       cd(i,r) Private demand
                gd(i,r) Public demand
                td(i,r) Transportation demand;


cd(i,r) = vpm(i,r) * C.L(r) * PC.L(r) * pc0(i,r) 
                        / ( PA.L("c",i,r) * (1 + tp(i,r)) );
gd(i,r) = vgm(i,r) * G.L(r) * PG.L(r) * pg0(i,r) 
                        / ( PA.L("g",i,r) * (1 + tg(i,r)) );

td(i,r) = vst(i,r) * YT.L * PT.L / (PX.L(i,r)$(1/eta>0) + PY.L(i,r)$(1/eta=0));
